您的位置:首页 > Web前端 > JavaScript

Javascript Web Design

2016-04-24 22:23 363 查看
1. 在HTML call 在javascript里的 function

<input type="text" name="from" id="from" maxlength="5" placeholder="day-month" title="Optional" onkeyup="checkDate(this)"/>

function checkDate(caller){
var that = $(caller);
if(caller.id == 'from' || caller.id == 'to'){
if(caller.value.match(/^[0-9 -]+$/g)){that.css('border','none');}
else if(caller.value == ""){that.css('border','none');}else{that.css('border','red 1px solid');}
}


2. 在javascript里使用 html 里的id, id 不能是大写开头,否则会出现Error。

3. 使用php 与 Ajax 时,发送键不能为html里内建的submit,否则 将不能使Ajax成功连接上(TextStatus:Request failed: error)需要的url。

此外使用内建submit,有不好处:会造成request泄漏,submit后,会默认将form的内容serialize到当前地址的后缀处(以?开始)。

正确:<input type="button" name="submit" id="" onclick="userInput()"/>

不当:<input type="submit" name="submit" id="" onclick="userInput()"/>

4. PHP 里的variable 用 "Get" 得到 undefined error:
在PHP 的function 里用 global scope。 如:

global $year; echo($year);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: