2015-10-06 68 views
-3

在這裏,我正在檢查刪除屬性的父母id。所以如何合併此代碼與字符串。如何添加字符串作爲jquery選擇器鏈功能?

var parentId = $(this).parent().parent().attr('id'); 
$("#"+parentId ".medicinetype-allergies input[type=checkbox]").removeAttr('checked'); 
+1

'$( 「#」 + +的parentId 「.medicinetype-過敏輸入[類型=複選框]」)。removeAttr( '檢查') ;'在parentId後添加了** + **,在'medica ...之前的空格... – Tushar

+0

http://stackoverflow.com/questions/5891840/how-to-use-javascript-variables-in-jquery-selectors –

+0

也添加HTML,問題可能是選擇器 – Tushar

回答

0

應該工作:

$("#" + parentId + " .medicinetype-allergies input[type=checkbox]").removeAttr('checked'); 

注意:你錯過了第二+運營商,這是用來連接字符串。不要忘記用空格分隔不同的選擇器。

+0

$(「#」+ parentId +「.None-allergies input [type = checkbox]」)。prop(「checked」,true); – user3222157

+0

如何使選中狀態爲true – user3222157

0

請確保 '+' 操作符,爲您的選擇

var parentId = $(this).parent().parent().attr('id'); 
$("#"+parentId+".medicinetype-allergies input[type=checkbox]").removeAttr('checked');