Webpage 请告诉我如何获取当前html页面标题并通过提交表单

Webpage 请告诉我如何获取当前html页面标题并通过提交表单,webpage,Webpage,请我想脚本是在javascript只。 我希望获得页面标题并将其传递给提交表单,以便在提交时,我可以看到用户发送请求的实际页面名称 试试这个 使用Jquery 或者用一般的方式 更新 您可以像这样在表单中附加项 function AppendHiddenField(theForm) { // Create a hidden input element, and append it to the form: var input = document.createElement('i

请我想脚本是在javascript只。 我希望获得页面标题并将其传递给提交表单,以便在提交时,我可以看到用户发送请求的实际页面名称

试试这个 使用Jquery

或者用一般的方式

更新

您可以像这样在表单中附加项

function AppendHiddenField(theForm) {
    // Create a hidden input element, and append it to the form:
    var input = document.createElement('input');
    input.type = 'hidden';
    input.name ='PageTitle';
    var Pagetitle = document.getElementsByTagName("title")[0].innerHTML;
    input.value = Pagetitle;
    theForm.appendChild(input);
}
在提交表单之前,可以使用此函数将隐藏字段追加到表单中

更新这里是工作代码 您需要为表单分配一个id

JS

HTML


我需要javascript,这可能吗?通过一般的方式,我怎样才能把标题写到表单上呢?我已经更新了我的答案,你可以在提交表单之前使用这个功能。我已经尝试过你给我的东西,但仍然不起作用,这是我的代码:learnmoreng.com/forum2_theme_111582926.xhtml?tema=3如果你能编辑错误并发布完整的工作代码,我会很高兴的,非常感谢。
var title = document.getElementsByTagName("title")[0].innerHTML;
function AppendHiddenField(theForm) {
    // Create a hidden input element, and append it to the form:
    var input = document.createElement('input');
    input.type = 'hidden';
    input.name ='PageTitle';
    var Pagetitle = document.getElementsByTagName("title")[0].innerHTML;
    input.value = Pagetitle;
    theForm.appendChild(input);
}
window.onload = function(){
var input =document.createElement('input');
var frm = document.getElementById("myform");
input.type = 'hidden';
input.name ='PageTitle';
input.value = document.title;
frm.appendChild(input);
}
<form id="myform" method="submit" action="http://www.facebook.com/sharer/sharer.php?u=http://lmn.9nty.com/?testlink=www.learnmoreng.com/site_rp.xhtml"> <input type="text" name="l" value=":getid-url:"
maxlength="20" size="9"/>
<input type="submit" value="Share" style="background-color:#f3f4f5;padding:3;color:#339900;font-weight:italic"/></form>