我的网页中有两种类型的链接:
<div id="mybookings">
<a name="type1ID" href="4007" class="booking-deleteDraft">Delete Me</a>
<a name="type2ID" href="9001" class="booking-deleteDraft">Delete Me</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在写一个ajax提交,需要在POST中包含正确的数据.我如何要求JQuery执行以下操作:
$("#mybookings").on('click', '.booking-deleteDraft', function (e) {
e.preventDefault();
data: {
Type1ID: $(this).attr("href").val() // This gets the value of the href, but it should only get it where the name attribute is "type1"
Type2ID: $(this).attr("href").val() // This gets the value of the href, but it should only get it where the name attribute is "type2"
},
.....
Run Code Online (Sandbox Code Playgroud)
如何在Type1ID和Type2ID参数中获取正确的值?
有了这个css选择器a[name="type1"]和a[name="type2"]
data: {
Type1ID: $('a[name="type1"]').attr("href") // This gets the value of the href, but it should only get it where the name attribute is "type1"
Type2ID: $('a[name="type2"]').attr("href") // This gets the value of the href, but it should only get it where the name attribute is "type2"
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
947 次 |
| 最近记录: |