English 中文(简体)
如何获得微粒的超文本,包括投入的价值
原标题:How to get the HTML of a div, including value of inputs

我有:

<div id= myDiv >
  <input type= text  id= foo  size= 30  />
</div>

i) 操作这部法律:

($("#foo").val( bar );

如果我这样做的话:

alert($("#myDiv").html());

alert(document.getElementById( myDiv ).innerHTML);

我只收到<代码>foo<>/code>文本箱的价值仍然空白的原始版。 我愿收到一份最新版本的html,并附有一份<代码>=条码的特性,并添加到《 foo s html代码》。

如何做到这一点?

问题回答

您可以尝试直接确定价值参数,但我确信,仍然获得一定影响......html()或.inner/60/8的产出:

$( #foo ).attr( value ,  foo );

相反,为什么在 yourself中不添加:

var html = $( #foo ).html();
if (html.indexOf( value= ) == -1)
    html.replace(/^<input/,  <input value="  + $( #foo ).val() +  " ); 

您真的希望使用jquery(clone(功能。 这将让你打上头脑,然后在iBox插入你的 clo。

var clone = $( #myDiv ).clone();
$( #iBox ).append(clone);

为什么在产生超文本之前,不要将输入值财产复制到其属性? 请注意,这将改变您可能拥有的任何重新分类类型纽扣的影响。

我的理解是,你想展示“从div} = 酒吧”? 如果是这样的话,下面的法典在FF和IE都为我工作:

<html>
<head>
 <title>Hello</title>
 <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
 <script type="text/javascript"> 
  $(document).ready(function()
  {
   $("#foo").val( bar );
   alert(($(".myDiv").text()) + ($("#foo").val()));
  });
 </script>
</head>
<body>
 <div class= myDiv >
  Value = <input type= text  id= foo  size= 30  />
 </div>
</body>
</html>




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

热门标签