使用为输入设置的值属性获取HTML源代码 [英] Get HTML Source with Values attributes set for Input
问题描述
我使用jQuery将包含表单的HTML文档发送到C#WebService。
webService解析它并尝试读取表单中所有输入的value属性。
问题是我将HTML文档发送到web服务with
var HTMLDoc = document.getElementById('foo')。innerHTML;
并且它不返回带有value属性的输入。
例如,我得到了:
< input type =textid =foo/> gt ;
我想让JavaScript得到:
< input type =textid =foovalue =bar/>
当我做一些类似的事情时
<$ p $ 。p> 的document.getElementById( '富')的innerHTML;
这可能吗?任何想法?
您可以尝试它
$ b $ h1 HTML
< input type =textname =fooid =foo/>
在Jquery中:
var foo = $(#foo)。val();
alert(Jquery foo value:+ foo);
在JavaScript中:
var foo = document.foo.value;
alert(JavaScript foo value:+ foo);
I'm using jQuery to send an HTML document which contains a form to a C# WebService. The webService parse it and try to read "value" attribute of all inputs in the form.
The problem is that I send the HTML doc to the webservice with
var HTMLDoc = document.getElementById('foo').innerHTML;
And it does not returns the input with value attribute. For example, I got a :
<input type="text" id="foo" />
And I want the JavaScript to get :
<input type="text" id="foo" value="bar" />
when I do something like
document.getElementById('foo').innerHTML;
Is this possible ? Any idea ?
you can try it
HTML
<input type="text" name="foo" id="foo" />
in Jquery :
var foo = $("#foo").val();
alert("Jquery foo value : " + foo);
in JavaScript :
var foo = document.foo.value;
alert("JavaScript foo value : " + foo);
这篇关于使用为输入设置的值属性获取HTML源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!