English 中文(简体)
j 投入的价值
原标题:Get value of input in jQuery

当一个检查箱被点击时,我想转往另一页。

<script type="text/javascript"><!--
$(document).ready(function(){
    jQuery(".cbno").click(function(e){
        e.preventDefault();
        alert( test );
        alert(this.val());
//      window.location = this.val();
    });
});
//-->
</script>

<input type="checkbox" class="cbno" name="content" value="/map/?filter=all" />

Pretty simple - but I cannot figure out why the second alert does not produce any output? Internet Explorer says: "The object does not support the method val".

如果我使用的话,它就发挥了作用。 得到Attribute(价值)——为什么不与jquery val(价值)合作?

最佳回答

use

alert(jQuery(this).val());
问题回答

$>(this.val() or $(this.attr(“数值”) or this.getAttriute(“价值”) or this. Value 工作

请按(美元)和j Query(美元)计算。

<script type="text/javascript"><!--
$(document).ready(function(){
    $(".cbno").click(function(e){
        e.preventDefault();
        window.location = $(this).val();
    });
});
//-->
</script>

<input type="checkbox" class="cbno" name="content" value="/map/?filter=all" />

这不是一个 j子。 您需要使用美元。

变化:

alert(this.val());

:

alert($(this).val());


You can also simply use:

this.value

因此,你可以修改你们的法典。

$(document).ready(function(){
    jQuery(".cbno").click(function(e){
        e.preventDefault();
        alert(this.value);
        //window.location = this.value;
    });
});
$(document).ready(function(){
    jQuery(".cbno").click(function(e){
        e.preventDefault();
        alert( test );
        alert( $(this).val());
//      window.location = $(this).val();
    });
});

在事件中,这是与OM要素的联系,因此,你应当用它的方法制造一个 j子。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签