這對我來說很奇怪,當我選擇一個元素時,id
; jQuery代碼不起作用,但是當我通過classname
選擇它時,它的效果非常好!jquery select class but id
驗證碼:
<input name='daneshjou_number' class='daneshjou_number' type='text' >
此代碼的工作:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".is_daneshjou").change(function(){
//alert("The text has been changed.");
$(".daneshjou_number").prop('readonly', true);
});
});
</script>
但是這個代碼不工作:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".is_daneshjou").change(function(){
//alert("The text has been changed.");
$("#daneshjou_number").prop('readonly', true);
});
});
</script>
因爲元素沒有一個'ID'屬性! – 2015-03-03 08:39:21
其中是'? – 2015-03-03 08:39:49
我的天啊,我沒有看到它:))我是在jQuery代碼 – SoheilYou 2015-03-03 08:42:11