為什么無(wú)法修改type屬性?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
? ? <head>
? ? ? ? <title>live()方法綁定事件</title>
? ? ? ? <script src="http://libs.baidu.com/jquery/1.8.2/jquery.js" type="text/javascript"></script>
? ? </head>
? ? <body>
? ? ? ? <h3>live()方法綁多個(gè)事件</h3>
? ? ? ??
? ? ? ? <script type="text/javascript">
? ? ? ? ? ? $(function () {
? ? ? ? ? ? ? ? data={type:'text'};
? ? ? ? ? ? ? ? $("input").live
? ? ? ? ? ? ? ? (
? ? ? ? ? ? ? ? ? ? "click mouseout",data,function ()?
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? $(this).css("type",data.type);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? );
? ? ? ? ? ? ? ? $("body").append("<input id='btntest' type='button' value='點(diǎn)擊或移出就不可用了' />");
? ? ? ? ? ? });
? ? ? ? </script>
? ? </body>
</html>
2016-04-01
還有,一樓說(shuō)的很對(duì),不可能用css() ? 只可能用attr() ? 附一端代碼你理解下:
$(function () {
? ? ? ? ? ? ? ? var data={value:'test ?test'};
? ? ? ? ? ? ? ? $("input").live
? ? ? ? ? ? ? ? (
? ? ? ? ? ? ? ? ? ? "click",data,function ()?
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? alert(data.value);
? ? ? ? ? ? ? ? ? ? $(this).attr("value",data.value);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? );
? ? ? ? ? ? ? ? $("body").append("<input id='btntest' type='button' value='點(diǎn)擊或移出就不可用了' />");
? ? ? ? ? ? });
2016-04-01
查了好久:
首先:
type屬性是?read/write-once?的,?只在初始化時(shí)set。
要么用新的元素取代舊的元素
然后:?
jquery是無(wú)法input 標(biāo)簽的type屬性 ? 但是原生的 js 是可以的,但是只有firefox支持 ,IE下是不支持修改type屬性的. 如果非要改 ? 有一個(gè)解決辦法:變相改,就是 先把它刪了,然后創(chuàng)建一個(gè).嗯 就是這樣
2016-03-18
?$(this).css("type",data.type);?
css 只能添加樣式的屬性,這里應(yīng)該用元素屬性attr。