[馨郁星愿]js操作字符串~!~~速帮忙~
已知有一段字符串,比如:
<body>
<form name= "splogin " method= "post " ID= "Form1 ">
<input type= "hidden " id= "ddd " value= "333 " NAME= "ddd "/> </form>
</body>
</html>
我怎么通过js 取ddd的值?
注:以上字符串是通过XMLHttpRequest来取到的,怎么用js来操作,并取到值?
------解决方案--------------------var doc=XMLHttpRequest.responseXML;
var d=doc.selectNodes( "//html/body/form/input[@id= 'ddd '] ")[0];
//alert(d.length);
alert(d.getAttribute( "value "));
------解决方案--------------------同意楼上
但是你获取的文件必须严格按照XML标准
------解决方案--------------------同意楼上的
你的xml文件开头还需要加1个 <html>
------解决方案--------------------用正则吧
str = ' <form name= "splogin " method= "post " ID= "Form1 "> <input type= "hidden " id= "ddd " value= "333 " NAME= "ddd "/> </form> ';
reg = /id= "ddd "[ ]+value= "([^ "]+) "/i;
r=str.match(reg);
alert(r[1]);