简体   繁体   English

我正在尝试 .Find() 一个 Div 内的 TextArea

[英]I'm trying to .Find() a TextArea inside a Div

 <div id='bla'>
   <textarea type='text' style='text-align:center; color:black; width:90px; border:1px     
    solid transparent; font-size:11px; margin:2px'>this is a test</textarea>
 </div>​​​​​​​​​​​​

 alert($('bla').find('textarea').css('border'))

but for some reason this returns 'undefined' any ideas why?但出于某种原因,这会返回“未定义”任何想法为什么? I'm defining a border inside that style... :/我正在该样式中定义边框...:/

jsfiddle: http://jsfiddle.net/foreyez/yWgqD/ jsfiddle: http : //jsfiddle.net/foreyez/yWgqD/

Missed the ID selector ( # ) before bla ...bla ... 之前错过了 ID 选择器 ( # )

Instead, use the following:相反,请使用以下内容:

alert($('#bla textarea').css('border'))

您需要使用# ID 选择器:

$("#bla").find("textarea").css("border");

The selector only won't cut it, you forgot the dom ready part too.选择器不会削减它,你也忘记了 dom 准备好的部分。

$(function() {
    alert($('#bla').find('textarea').css('border'));
});

http://jsfiddle.net/yWgqD/1/ http://jsfiddle.net/yWgqD/1/

Also as selector this is cleaner同样作为选择器,这更干净

$('#bla textarea') $('#bla textarea')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在textarea中输入时,KnockoutJS绑定到div - KnockoutJS bind to div as I'm typing in textarea 我正在尝试使用 jquery 更改 textarea 内标签的顺序,但它不起作用? - I'm trying to change order of tags inside textarea with jquery, but it's not working? Javascript 问题我正在尝试从文本区域中提取字符串 - Javascript problem I'm trying to extract a string from a textarea 元素阻塞 div 我正在尝试 hover 上? - Elements blocking div I'm trying to hover on? 我在div中找不到结果 - I'm unable to find a result in my div 我正在尝试使用jscript从另一个文本区域复制数据后尝试清除文本区域,但无法清除第二个文本区域 - I'm trying to clear textarea after copying data from another textarea using jscript but unable to clear second textarea jQuery在div内添加textarea - JQuery add textarea inside a div 我正在尝试从动态生成的表单中获取Textarea值,但是当我单击按钮时,什么也没有发生 - I'm trying to get Textarea value from a dynamically generated form but when I click the button nothing happens 我正在尝试检测div是否包含iFrame - I'm trying to detect whether a div contains an iFrame 我正在尝试显示选择到 div 中的每个复选框的值 - I'm trying to display the value of each checkbox selected into a div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM