有一个网站,其中有:
<html>
<body>
<form action="/action_page.php">
First name: <div class="col-md-8 col-sm-8 col-xs-6"><strong><input type="text" class="no-style" value="John"></strong></div>
Last name: <div class="col-md-8 col-sm-8 col-xs-6"><strong><input type="text" class="no-style" value="Miller"></strong></div>
Email: <div class="col-md-8 col-sm-8 col-xs-6"><strong><input type="text" class="no-style" value="j.miller@gmail.com"></strong></div>
<input type="submit" value="Send">
</form>
</body>
</html>
是否可以从输入值(John,Miller,j.miller @ gmail.com)中抓取数据并将其显示在我的页面中(也许将该网站放到iframe中并从中抓取?),或者使用类似的方法:
// Get HTML from page
$.get( 'http://example.com/', function( html ) {
// Loop through elements you want to scrape content from
$(html).find("ul").find("li").each( function(){
var text = $(this).text();
// Do something with content
} )
} );
我不知道。我对javascript不好。还有好处:每次刷新的输入值都不同。我可以从100次刷新中提取数据吗?谢谢您的帮助!
答案 0 :(得分:1)
我会假设您需要从输入元素中获取数据,然后在您网站的其他地方使用它
您可以使用jquery .val()函数轻松地做到这一点
这是一些示例代码
<form id="my-form">
name: <input type="text" id='test-input'/>
<input type="submit" />
</form>
<script>
var input;
$('#my-form').on('submit', function() {
input = $('#test-input').val();
});
</script>
然后,您可以随时使用该变量,无论是缓存数据还是用于改善用户体验
答案 1 :(得分:0)
获取值和var _value = $('#elementId').val();
,并在页面$('#elementID').val(_value);
或$('selector').text(_value);
上的任何位置使用它