Tag: jQuery

val()如何返回Number?

在val 文档中写下这个描述: .val()返回:String,Number,Array 我试图得到一个Number ,但它似乎只返回string ,有什么我做错了吗? $('#gdoron').val('1'); alert($('#gdoron').val() === '1'); // true alert(typeof $('#gdoron').val()); // string. $('#gdoron').val(1); alert($('#gdoron').val() === 1); // false alert(typeof $('#gdoron').val()); // string (not "number"!) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="gdoron" /> 我的问题是: val()如何返回数字作为文档说? 问题不在于如何parsingstring。

jQuery绑定到Paste Event,如何获取粘贴的内容

我有一个jQuery的标记标记插件,我想绑定到粘贴事件正确添加项目。 我可以像这样绑定到粘贴事件: .bind("paste", paste_input) … function paste_input(e) { console.log(e) return false; } 我如何获得实际粘贴的内容值?

jQuery查找与上下文select

有以下的HTML片段 <div class="something"> <p>Some text</p> </div> <div class="somethingElse"> <p>some other text</p> </div> 我认为下面的jquery片段是相同的(将有相同的结果): $(".something").find("p").css("border", "1px solid red"); $("p", ".something").css("border", "1px solid red"); 我的问题是,一个片段是否比另一个片段好,应该使用

JQuery Ajax发送GET而不是POST

以下代码触发GET而不是POST HTTP请求。 function AddToDatabase() { this.url = './api/add'; } AddToDatabase.prototype.postData = function(dataToPost) { $.ajax({ type: "POST", url: this.url, data: dataToPost, context: this, success: this.onSuccess }); }; var AddToDatabase = new AddToDatabase(); data = {data: 'coucou'}; AddToDatabase.postData(data); 为什么,我怎样才能得到一个POST? 我在Google Chrome Inspect和Firefox中看到检查浏览器发送GET。 这是从Chrome浏览器: 请求URL:http:// localhost / SAMPLE-CODES / UPDATE%20MYSQL / api / add /请求方法:GET状态码:200 OK 解决了 名为“./api/add”的URL实际上是发布到“./api/add/index.php”。 […]

如果连接是本地主机,如何检查与JavaScript?

如果页面加载在我的本地机器上,我想检查我的javascript。 我想这样做的原因是,当我开发我喜欢确保我的服务器端(C#)validation工作正常。 所以我喜欢看到客户端和服务器端出现错误。 所以当我testing时,我有一个标志在我的jQueryvalidation的东西,只是总是让无效的数据通过。 这样一来我就可以看到客户端和服务器错误。 但是现在我需要从开发到生产的时候手动去换。

Twitter Bootstrap模式将html内容推送到左侧

如果我打开一个模式对话框,通过Twitter Bootstrap,我注意到它将页面的所有html内容(即container )左移一点,然后在closures之后将其恢复正常。 但是,这只有在浏览器宽度足够大以至于不在“移动”(即最小)媒体查询时才会发生。 这发生在FF和Chrome的最新版本(还没有testing过其他浏览器)。 你可以在这里看到这个问题: http : //jsfiddle.net/jxX6A/2/ 注意:您必须增加“结果”窗口的宽度,以便切换到“med”或“large”媒体查询CSS。 我已经根据Bootstrap站点上显示的示例设置了页面的HTML: <div class='container'> <div class='page-header'> <h4>My Heading</h4> </div> <div id='content'> This is some content. </div> <div class='footer'> <p>&copy; 2013, me</p> </div> </div> 我猜这不应该发生,但我不知道我做错了什么。 编辑:这是一个已知的错误,更多(和最新)的信息,请参阅: https : //github.com/twbs/bootstrap/issues/9855

使用jQuery $(this)和ES6箭头函数(lexical this binding)

使用ES6的箭头函数与词法this绑定是伟大的。 不过,我刚才遇到一个问题,使用它与一个典型的jQuery点击绑定: class Game { foo() { self = this; this._pads.on('click', function() { if (self.go) { $(this).addClass('active'); } }); } } 改为使用箭头function: class Game { foo() { this._pads.on('click', () => { if (this.go) { $(this).addClass('active'); } }); } } 然后$(this)被转换成ES5(self = this)types的闭包。 是否让Traceur忽略“$(this)”来进行词法绑定?

Bootstrap的JavaScript需要jQuery 1.9.1或更高版本

我有我的代码中的所有必要的文件,我仍然得到这个错误: Bootstrap的JavaScript需要jQuery 1.9.1或更高版本 这是我的代码: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js'></script> <script src="js/jquery.responsiveiframe.js"></script> <script src="js/ios-orientationchange-fix.js"></script> 任何人之前有这个错误? 我可以尝试下载一个本地副本,而不是使用CDN链接,但这是真的没有必要,再加上我想知道为什么这是行不通的! 编辑:我试过很多不同的图书馆,我发布的是我试过的最后一个

jquery清除input的默认值

我怎样才能清除焦点与jQuery的input表单的默认值,并按下提交button时再次清除? <html> <form method="" action=""> <input type="text" name="email" value="Email address" class="input" /> <input type="submit" value="Sign Up" class="button" /> </form> </html> <script> $(document).ready(function() { //hide input text $(".input").click(function(){ if ($('.input').attr('value') == ''){ $('.input').attr('value') = 'Email address'; alert('1');} if ($('.input').attr('value') == 'Email address'){ $('.input').attr('value') = ''} }); }); </script>

如何使用jQuery获取指定标签名称的父元素?

我想获得一个具有指定标签名称的元素的父项。 示例代码: <table> <tr> <td> <input type='button' id='myId' /> </td> </tr> </table> 现在我想要这样的东西: $('#myId').specificParent('table'); //returns NEAREST parent of myId Element which table is it's tagname.