English 中文(简体)
on on on child
原标题:onClicking on a parent div, get child value- without String manipulation

我如何能够从小孩的亲子上点击事件获得儿童投入的价值。

<>Dynamic RUS

<div class="tableRowOdd">
  <input type="hidden" value="28"> 

  04/11/2012
</div>

<>JS

$( #historyContainer .tableRowOdd ).live(  click , function(e) {

     // Here I want to get the hidden-input s value directly  
     // something like- $(this+ input ).val()
     console.log( $(this) );

});

Don t Hope to dostrong, from $(this).html()。

请提供帮助。

最佳回答
$( #historyContainer .tableRowOdd ).live(  click , function(e) {
     console.log( $(this).find( input ).val() ); // or .text()
});

指出,这将通过所有投入加以利用。 如果你只想:

$( #historyContainer .tableRowOdd ).live(  click , function(e) {
     console.log( $(this).find( input ).first().val() ); // or .text()
});
问题回答

a) 通过家庭补助:

$( #historyContainer .tableRowOdd ).live(  click , function(e) {

     // if you have more inputs and wanna get the hidden 
     console.log( $(this).find( input[type="hidden"] ).val() );
});

<代码>$(原文):find(投入).val()应当退还您。

<>说明: 使用<代码>。 如果你使用jQuery 1.7或使用,则使用<>delegate。 <代码>.live不是首选功能。

旧版本使用.delegate

$( #historyContainer ).delegate( .tableRowOdd ,  click , function(e) {
     $(this).find( input ).val()
     console.log( $(this) );
});

使用<代码>。 For jQuery 1.7

$( #historyContainer ).on( click ,  .tableRowOdd , function(e) {
     $(this).find( input ).val()
     console.log( $(this) );
});

你可以这样做;

$(this).find( input ).val()




相关问题
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!

热门标签