douxun3496 2012-08-06 15:29
浏览 54

有没有办法在按钮加载时将button()jquery ui函数应用于按钮?

Basically. I have a javascript loop that posts to a php script. To append on the response to a DIV in a log. The response has a button inside it. The problem is, when a new response is made and appended, the jquery button function makes all the previous appended buttons larger. (Probably because it's calling the jquery button() function again on the same DIV elements.)

Is there a way to apply the button() jquery ui function to a button when it's loaded? (Instead of applying it to every element with the same name?)

This php is quite similar to the following (but this is shortened.) Just to give you an idea of what the php script does.

<?php

    echo "<script type='text/javascript'>
        function addButton(x) {
            x = this;
            $(x).button({            
                icons: {                
                    primary: 'ui-icon-alert'                    
                }
            });
        }
        </script><div id='chat_wrap' class='message".$id."' hidden='true'>";


if ($query_run = mysql_query($finalchatq)) {
    if (mysql_num_rows(mysql_query($finalchatq)) > 0) {
        $counter = 0;
        $amount = array();
        while ($query_rows = mysql_fetch_assoc($query_run)) {
            $time1 = $query_rows['time'];
            $time2 = substr_replace($time1, " : ", 10, 1);
            $time = str_ireplace('.', '/', $time2);
            $text = str_ireplace('removem', '', $query_rows['text']);
            $id = $query_rows['id'];

            if($query_rows['type']=='notice') {

            echo "<div  selectable='false'><div id='date'><div id='notice'>NOTICE:</div>Sent At: ".$time."</div><div id='Nchat_message'><div id='chat_text'>".$text."</div><img id='charhead' src='camperhead.php?id=".$query_rows['who']."' id='charhead'></img></div>";
            echo "<div id='controls'>";

            if(userIsA('admin')||userIsA('mod')) {
                echo "<input hidden='hidden' name='idtodel' value='".$id."'></input><input type='button' value='DELETE' id='delete_button'></input>";
            } else {

            }

            echo "</div></div></div><br/><br/>";         
        }
        if($query_rows['type']=='normal'){      
            echo "<div selectable='false'><div id='date'><div id='by'>".getUserFieldById($query_rows['who'], 'camper_name').":</div>Sent At: ".$time."</div><div id='chat_message'><div id='chat_text'>".$text."</div><img id='charhead' src='camperhead.php?id=".$query_rows['who']."' id='charhead'></img>";
            echo "<div id='controls'>";

            if(userIsA('admn')||userIsA('md')) {
                echo "<button id='delete_button' class='dpp2'  onclick='delCom(".$id.")'>Delete</button>";
            } else {
                echo "<button id='report_button' onload='addButton(this)' onclick='reportCom(".$id.")'>REPORT</button>";
            }
    echo "</div></div></div></div></div><br/><br/>";
        }
    }
    echo "</div>";
}
}
}

?>

I hope I've made my question clear enough, if you have any concerns please post a comment and I'll reply as soon as I can.

  • 写回答

1条回答 默认 最新

  • doubangzhang6992 2012-08-06 16:04
    关注

    Try using the .on() function in jQuery to define it when created http://api.jquery.com/on/

    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码