Javascript和php引用阻止函数的执行
Javascript and php quotations preventing the execution of functions
我正在尝试使用以下代码构建注册表,我仍处于开始阶段。我在执行 PHP echo 语句中的任何 JavaScript 代码时遇到了非常困难的问题。
我尝试使用斜杠''
和 '"
转义 javascript 函数中的单引号和双引号,这适用于顶级 javascript 函数,但是一旦我添加了其他两个函数并应用了相同的逻辑,所有 javascript 函数都停止工作。
有人可以建议防止问题并轻松执行php echo语句中的javascript代码的最简单方法是什么?
<?php
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function validateEmail(email) {
var re = /^(([^<>()[']''.,;:'s@'"]+('.[^<>()[']''.,;:'s@'"]+)*)|('".+'"))@(('[[0-9{1,3}'.[0-9]{1,3}'.[0-9]{1,3}'.[0-9]{1,3}'])|(([a-zA-Z'-0-9]+'.)+[a-zA-Z]{2,}))$/;
if(re.test(email)) {
document.getElementById(''result'').innerHTML = ''<img src='"http://www.customotion.com/green_check_small.png'" style='"width:15px;'"/> Valid'';
} else {
document.getElementById(''result'').innerHTML = ''<img src='"http://biglistbigsales.com/m/templates/GPT/images/x_xMarkRed4.png'" style='"width:15px;'"/> Invalid'';
}
}
</script>
</head>
<body>
<div id="main-container">
<div id="body-container" style="padding-bottom:150px; height:800px;">
<div style="height:100px; margin:0px auto;">
<img class="reg-step" style="width:100%;" src="images/step1.png">
</div>
<div style="margin-left:110px;">
<span style="font-size:24px;" class="smallheading">Tell Us About Yourself</span>
<br/><span style="font-size:13.5px;"><i>*All fields required</i></span>
</div>
<form method="post" action="registernew.php">
<div style="margin:0px auto; margin-left:110px; border:1px solid blue; float:left; font-size:12px; width:500px;">
<div style="border:1px solid blue; float:left; width:80%;">
<div style="float:left; border:1px solid red;">
First Name:
<br/><input type="text" style="width:140px;" name="fname" />
</div>
<div style="float:right; margin-right:50px; border:1px solid red;">
Last Name:
<br/><input type="text" style="width:140px;" name="lname" />
</div>
</div>
<div style="border:1px solid blue; float:left; margin-top:20px; width:50%;">
<div style="float:left; border:1px solid red;">
City:
<br/><input type="text" style="width:170px;" name="fname" />
</div>
<div style="float:right; border:1px solid red;">
State:
<br/>';
include('inc/statedropdown.inc.php');
echo' </div>
</div>
<div style="float:left; width:100%;">
<br/>Company Name:<br/> <input type="text" name="fname" style="width:150px;"/>
<br/><br/>E-mail Address:<br/> e-mail:<br/><input id="email" type="text" onblur="validateEmail(this.value)" /><span id="result"></span>
<br/><br/>Phone Number:<br/> <input type="text" name="fname" style="width:110px;" />
<br/><br/>Password:<br/><input type="password" name="fname" />
<br/><br/>Confirm Password:<br/><input type="password" name="lname" />
<br/><input type="submit" value="Next Step" style="background-color:#ebda5f; color:blue; margin:15px 0px 0px 20px;">
</div>
</form>
</div>
</div>
</div>
</body>
</html>';
?>
仅在需要时使用 <?php ?>
标记。任何不在标签内的内容都会被回显并被视为 HTML。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function validateEmail(email) {
var re = /^(([^<>()[']''.,;:'s@'"]+('.[^<>()[']''.,;:'s@'"]+)*)|('".+'"))@(('[[0-9{1,3}'.[0-9]{1,3}'.[0-9]{1,3}'.[0-9]{1,3}'])|(([a-zA-Z'-0-9]+'.)+[a-zA-Z]{2,}))$/;
if(re.test(email)) {
document.getElementById(''result'').innerHTML = ''<img src='"http://www.customotion.com/green_check_small.png'" style='"width:15px;'"/> Valid'';
} else {
document.getElementById(''result'').innerHTML = ''<img src='"http://biglistbigsales.com/m/templates/GPT/images/x_xMarkRed4.png'" style='"width:15px;'"/> Invalid'';
}
}
</script>
</head>
<body>
<div id="main-container">
<div id="body-container" style="padding-bottom:150px; height:800px;">
<div style="height:100px; margin:0px auto;">
<img class="reg-step" style="width:100%;" src="images/step1.png">
</div>
<div style="margin-left:110px;">
<span style="font-size:24px;" class="smallheading">Tell Us About Yourself</span>
<br/><span style="font-size:13.5px;"><i>*All fields required</i></span>
</div>
<form method="post" action="registernew.php">
<div style="margin:0px auto; margin-left:110px; border:1px solid blue; float:left; font-size:12px; width:500px;">
<div style="border:1px solid blue; float:left; width:80%;">
<div style="float:left; border:1px solid red;">
First Name:
<br/><input type="text" style="width:140px;" name="fname" />
</div>
<div style="float:right; margin-right:50px; border:1px solid red;">
Last Name:
<br/><input type="text" style="width:140px;" name="lname" />
</div>
</div>
<div style="border:1px solid blue; float:left; margin-top:20px; width:50%;">
<div style="float:left; border:1px solid red;">
City:
<br/><input type="text" style="width:170px;" name="fname" />
</div>
<div style="float:right; border:1px solid red;">
State:
<br/>
<?php include('inc/statedropdown.inc.php'); ?>
</div>
</div>
<div style="float:left; width:100%;">
<br/>Company Name:<br/> <input type="text" name="fname" style="width:150px;"/>
<br/><br/>E-mail Address:<br/> e-mail:<br/><input id="email" type="text" onblur="validateEmail(this.value)" /><span id="result"></span>
<br/><br/>Phone Number:<br/> <input type="text" name="fname" style="width:110px;" />
<br/><br/>Password:<br/><input type="password" name="fname" />
<br/><br/>Confirm Password:<br/><input type="password" name="lname" />
<br/><input type="submit" value="Next Step" style="background-color:#ebda5f; color:blue; margin:15px 0px 0px 20px;">
</div>
</form>
</div>
</div>
</div>
</body>
</html>
相关文章:
- 等待回调函数执行
- 暂停函数执行流程,直到ajax请求完成
- Bigcommerce-是否可以在函数执行后更改文本
- 如何对jquery中的未命名函数执行.call()
- 等待函数执行后再继续
- mootools类型的函数将文本作为函数执行
- 停止从另一个函数执行Javascript函数
- Jquery回调函数执行多次
- 如何使即兴 jquery 暂停当前函数执行
- JavaScript 双函数执行
- 来自函数 Javascript 的 NaN 返回值 ||函数执行顺序
- 如何在 JS 中调用 2 次或更多次时延迟函数执行
- 函数执行的次数超出预期
- JS中函数执行错误
- 为什么这个函数执行了两次
- 从子函数执行父函数;t更新父级'的属性
- 如何在jQuery函数执行's处于活动状态
- 使用javascript函数执行php文件
- jQuery函数执行顺序
- javascript中同步函数执行中的问题