English 中文(简体)
在检查箱后查阅文本
原标题:Accessing Text Nodes Next to Checkboxes, JQuery [duplicate]
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
How do I select text nodes with jQuery?

我正试图将正文中的数据移到关于筛选检查箱的检查箱旁。 我正在使用jquery。 我所尝试的方法列于下文,其结果是我收到的。

<input class="item" type="checkbox" /> Category 1
<input class="item" type="checkbox" /> Category 2


<script>
  $( .item ).click(function(){
      if($(this).attr( checked ))
      {
         $( #list ).append("<span>" + $(this).next() + "<span><br/>")
         //$(this).next() just writes "[object Object]"
         //$(this).next().text() doesn t write anything
         //Also tried $(this).nextSibling.nodeValue but throws "Cannot access property of undefined"
      }
      else
      {
          //This is remove the item from the list on uncheck 
      }
  });
</script>
最佳回答

考虑改为

<input class="item" type="checkbox" id="cat_one" name="cat_one" /> <label for="cat_one">Category 1</label>
<input class="item" type="checkbox" id="cat_two" name="cat_two"/> <label for="cat_two">Category 2</label>

<label for="cat_one"><input class="item" type="checkbox" id="cat_one" name="cat_one" /> Category 1</label>
<label for="cat_two"><input class="item" type="checkbox" id="cat_two" name="cat_two"/> Category 2</label>

因此,你用一块石块杀死了两个鸟类:(a) 您的标记远比以往好,(b) 可以通过<条码><<>/条码>的内容。

第一种变量见:。 http://jsfiddle.net/skip405/DjWcg/

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签