根据引用页面值自动选择复选框?
我正在制作一个电子邮件系列注册表单,需要根据用户来自的页面预先选中一个复选框。
看起来表单已经设置为跟踪用户来自哪个页面,因为它包含以下内容:
<input type="hidden" name="referring_page" value="<?php if (isset($_POST['referring_page'])) { echo $_POST['referring_page']; } else { echo $_SERVER['HTTP_REFERER']; }?>" />
复选框全部看起来像这样:
<div class="emailOption"><input type="checkbox" name="seo" id="seo" value="seo" /> SEO Series</div>
<div class="emailOption"><input type="checkbox" name="ppc" id="ppc" value="ppc" /> PPC Series</div>
我想根据引用页面网址。我对 PHP 和 jQuery 都很陌生,但该网站正在使用这两种方法,因此两者都可以作为解决方案。
非常感谢您的帮助!
I'm working on an email series signup form that needs to have a checkbox pre-checked depending on the page the user is coming from.
It looks like the form is already set up to track which page the user is coming from, as it contains this:
<input type="hidden" name="referring_page" value="<?php if (isset($_POST['referring_page'])) { echo $_POST['referring_page']; } else { echo $_SERVER['HTTP_REFERER']; }?>" />
The checkboxes all look like this:
<div class="emailOption"><input type="checkbox" name="seo" id="seo" value="seo" /> SEO Series</div>
<div class="emailOption"><input type="checkbox" name="ppc" id="ppc" value="ppc" /> PPC Series</div>
I would like to add the attribute checked="yes" to a single checkbox depending on the referring page url. I'm new to both PHP and jQuery, but the site is using both so either would work for a solution.
Thanks a lot for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我推荐 PHP,因为您正在预先检查。也就是说,如果您已经拥有逻辑并可以访问服务器端代码,则没有理由在页面加载后使用 JavaScript 执行此操作。
与隐藏输入类似:
I'd recommend PHP since you are pre-checking. That is to say there's no reason to do this with JavaScript after page load if you already have the logic and access to server-side code.
Similar to the hidden input:
在这种情况下您可以使用 jQuery。
尝试告诉我你的结果。 :)
You can use jQuery on this case.
Try and tell me about your result. :)
假设“来自 URL”您的意思是 seo 和 ppc 是 post 参数,这就是您需要的:
Assuming by "from the URL" you mean that seo and ppc are post parameters, this is what you need: