我有两个不同的页面,mouth.html和nose.html。我想从mouth.html得到一个名字。因此,当用户访问nose.html时,它会从nose.html中的mouth.html中打印出该地点的名称。我怎么能在Javascript中做到这一点?试图获取标签名称但不工作
这是mouth.html代码
<h1 class="man" style="clear:both;">{{ moot.name }}</h1>
在nose.html,我试过,但它不是在nose.html工作
<script language="javascript">
$("h1.man").load("mouth.html",function(data){
var value=$(data).find("h1.man").attr("man")
});
</script>
全码
<head>
<script language="javascript">
$.get('mouth.html', function(data) {
var mootName = $(data).text();
// Do something with mootName here
alert(mootName);
});
</script>
</head>
<body>
<form action="." method="POST">
{% csrf_token %}
<div class="post-fed">
<p><label for="id_event_date">Event date:</label><input type="text" name="event_date" id="id_event_date" /><span class="helptext">E.g 2012-01-00.YYYY/MM/DD</span></p>
<p><label for="id_end_date">End date:</label><input type="text" name="end_date" id="id_end_date" /><span class="helptext">E.g. 2012-01-00.YYYY/MM/DD</span></p>
<p><label for="id_event_information">Event information:</label><textarea id="id_event_information" rows="10" cols="40" name="event_information"></textarea><span class="helptext"> E.g. eating etc</span></p>
<p><label for="id_full_name">Full name:</label><input id="id_full_name" type="text" name="full_name" maxlength="100" /></p>
<p><label for="id_e_mail">Email:</label></th><td><input id="id_e_mail" type="text" name="e_mail" maxlength="100" /></p>
<p><label for="id_phone_no">Phone no:</label></th><td><input id="id_phone_no" type="text" name="phone_no" maxlength="100" /></p>
<input type="submit" class="put" value="Send"/>
</form>
</div>
</body>
'var value = ...'什么也看不见。它只是声明一个变量,然后由于函数结束而立即丢弃该变量。 – 2013-03-27 23:06:41
只需注意,.attr(“man”)将获得属性man的值,如
,这两种方法都不是有效的html。 尝试使用.attr(“class”)来获取man值或.text()以获取内部文本。不知道你想从.attr(..)得到什么样的价值,也可以看到其他解决方案的其他答案。 – 2013-03-27 23:36:59我认为你需要澄清你的问题。你想从mouth.html获得'{{moot.name}}',然后在nose.html中做什么?记录它?警报?修改你的页面的一部分? – ernie 2013-03-27 23:39:05