我想确定用户从哪个网站提交了联系表格。
联系表格是一个包含文件 (.shtml),该文件正在两个不同的网站上使用。由于它只有一个文件(包含),javascriptif...else
语句或switch
语句会这样做吗?如果是这样,它会怎么写?
我是 JavaScript 新手,不需要写太多东西,所以希望能得到语法方面的帮助。
我考虑过在一个包括联系表单上添加两个隐藏字段,其中包含两个不同站点的 ID:
html
<input type="hidden" data-id="new_student_signup" name="student_signup" value="" />
<input type="hidden" data-id="existing_student_signup" name="existing_student_signup" value="" />
js
if(data-id="new_student_signup"){
// this user came from the new student website
code if this condition is true
}
else if(data-id="existing_student_signup"){
// this user came from the existing student website
code if this condition is true
}
或者我应该为另一个网站创建一个新的包含文件并将隐藏字段添加到该文件而不是在一个包含上使用 javascript?
我承认,对于像我这样的 JavaScript 新手来说,这似乎是最容易的,但我确实喜欢学习更多 JavaScript 的想法。