Questions tagged «javascript»

有关在ECMAScript(JavaScript / JS)及其各种方言/实现(不包括ActionScript)中进行编程的问题。此标记很少单独使用,但最常与标记[node.js],[jquery],[json]和[html]关联。


4
VueJS如何在v-for中使用计算属性
如何在列表中使用计算属性。我正在使用VueJS v2.0.2。 这是HTML: <div id="el"> <p v-for="item in items"> <span>{{fullName}}</span> </p> </div> 这是Vue代码: var items = [ { id:1, firstname:'John', lastname: 'Doe' }, { id:2, firstname:'Martin', lastname: 'Bust' } ]; var vm = new Vue({ el: '#el', data: { items: items }, computed: { fullName: function(item) { return item.firstname + …

7
单击link_to帮助器后,Rails,JavaScript无法加载
当我在rails中使用link_to帮助器时,加载JavaScript时遇到了一些麻烦。当我手动输入带有'localhost:3000 / products / new'的URL或重新加载页面时,将加载javascript,但是当我经过如下所示的链接时,jQuery$(document).ready将不会加载到新页面上。 Link_to,当我单击此链接时,javascript无法加载: <%= link_to "New Product", new_product_path %> products.js文件 $(document).ready(function() { alert("test"); }); 任何帮助将非常感激。提前致谢!

4
验证单选按钮AngularJS
这似乎应该很容易,但是我没有找到答案。我有一个表格,需要核实是否已从广播组中进行选择。我尝试在单选按钮上使用'required'属性,但是在验证表单后,除非所有单选按钮都被选中(设计上是不可能的),否则它将抱怨。 在AngularJS中验证无线电组选择的正确方法是什么? <form name="myForm" ng-submit="submitForm()" ng-controller="ExampleController"> <input type="radio" ng-model="color" value="red" required> Red <br/> <input type="radio" ng-model="color" value="green" required> Green <br/> <input type="radio" ng-model="color" value="blue" required> Blue <br/> <tt>color = {{color | json}}</tt><br/> <button type="submit">Submit</button> </form> 单击Plnkr中的“提交”按钮将显示该行为。 http://plnkr.co/edit/3qcIbMvJk19OvokcHe2N?p=预览

2
使用DOM将SVG元素添加到现有SVG中
我有一个类似于以下代码的HTML构造: <div id='intro'> <svg> //draw some svg elements <svg> </div> 我希望能够使用javascript和DOM向上面定义的SVG中添加一些元素。我该怎么做?我在想 var svg1=document.getElementById('intro').getElementsByTagName('svg'); svg1[0].appendChild(element);//element like <line>, <circle> 我对使用DOM或如何创建要传递给appendChild的元素不是很熟悉,因此请帮助我解决这个问题,或者向我展示解决该问题的其他替代方法。非常感谢。
78 javascript  html  dom  svg 

20
Internet Explorer 8中的jQuery问题
我正在尝试让我的jQuery函数在IE8上运行。我正在从Google的服务器(http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js)加载库。 将$(function(){})永远不会被调用。相反,我得到一个错误Object expected。我打开开发人员并typeof $在控制台中运行,然后显示为undefined。 我尝试去其他我知道使用jQuery(jquery.com)的网站,这些网站都可以使用,在这里我可能会缺少一些东西吗?

5
JSPlugin.3005发生错误
我在服务器2008r2上安装了IE11。我试图使用IE11进行调试,但出现以下错误。我在“ Dom资源管理器”选项卡中遇到的错误是: 诊断: Exception in window.onload: Error: An error has ocurredJSPlugin.3005 堆栈跟踪: Error: An error has ocurredJSPlugin.3005 at getString (res://C:\Program Files\Internet Explorer\F12Resources.dll/23/pluginhost/plugin.f12.js:5021:27) at ToolWindowHelpers.loadString (res://C:\Program Files\Internet Explorer\F12Resources.dll/23/Common/CommonMerged.js:5803:13) at TabPanes..

5
您推荐哪些Javascript模板引擎?[关闭]
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实,参考或专业知识的支持,但是这个问题可能会引起辩论,争论,民意调查或扩展讨论。如果您认为此问题可以解决并且可以重新提出,请访问帮助中心以获取指导。 8年前关闭。 我想知道您对javascript模板引擎的看法,您认为哪种在性能方面更好? 我找到了一些人们进行基准测试的链接: http://jsperf.com/jquery-template-table-performance/15 http://jsperf.com/jquery-template-table-performance/8 http://www.viget.com/extend/benchmarking-javascript-templating-libraries/

6
如何强制脚本重新加载并重新执行?
我有一个页面正在从第三方(新闻提要)加载脚本。src脚本的url在加载时动态分配(根据第三方代码)。 <div id="div1287"> <!-- dynamically-generated elements will go here. --> </div> <script id="script0348710783" type="javascript/text"> </script> <script type="javascript/text"> document.getElementById('script0348710783').src='http://oneBigHairyURL'; </script> http://oneBigHairyURL然后从中加载的脚本创建并加载具有新闻提要中各种内容的元素,并以漂亮的格式等将其加载到其中div1287(传入ID“ div1287”,http://oneBigHairyURL以便脚本知道在何处加载内容)。 唯一的问题是,它只会加载一次。我希望它每n秒重新加载一次(从而显示新内容)。 所以,我想我会尝试一下: <div id="div1287"> <!-- dynamically-generated elements will go here. --> </div> <script id="script0348710783" type="javascript/text"> </script> <script type="javascript/text"> loadItUp=function() { alert('loading...'); var divElement = document.getElementById('div1287'); var scrElement = document.getElementById('script0348710783'); …

12
JavaScript无法在Android Webview中使用?
我正在尝试制作一个相对简单的iOS应用的Android版本,该应用使用Web视图,一些按钮,然后依靠对CMS的JavaScript调用。 但是我还停留在开发的早期阶段:Webview不能与javascript一起使用。我读了很多关于如何在Android Webview中启用JS的文章,但到目前为止还没有运气。 以下是我的一些代码: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebChromeClient(new WebChromeClient()); mWebView.setWebViewClient(new HelloWebViewClient() { @Override public void onPageFinished(WebView view, String url) { //Calling an init method that tells the website, we're ready mWebView.loadUrl("javascript:m2Init()"); page1(mWebView); } }); mWebView.loadUrl("http://my_url/mobile/iphone//app.php"); } private class HelloWebViewClient extends WebViewClient …

8
从JavaScript中的日期中减去天,月,年
有人知道一种简单的约会方式(例如今天)并回溯X天,X个月和X年的简单方法吗? 我已经尝试过: var date = new Date(); $("#searchDateFrom").val((date.getMonth() -1 ) + '/' + (date.getDate() - 6) + '/' + (date.getFullYear() - 1)); 但是我得到一个负日期,例如今天的输出是: 2015年3月3日 有什么建议吗? 谢谢。
78 javascript 

2
如何禁用特定行的ts规则?
Summernote是一个jQuery插件,我不需要它的类型定义。我只想修改对象,但TS不断抛出错误。下面的行仍然给我:“类型'jQueryStatic'上不存在属性'summernote'。” 错误。 (function ($) { /* tslint:disable */ delete $.summernote.options.keyMap.pc.TAB; delete $.summernote.options.keyMap.mac.TAB; /* tslint:enable */ })(jQuery) 编辑: 这是我的tsconfig.json { "compilerOptions": { "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, "module": "commonjs", "target": "es5", "allowJs": true, "noUnusedParameters": true }, "include": [ "js/**/*" ], "exclude": [ "node_modules", "**/*.spec.ts" ] }

5
JavaScript关联数组到JSON
如何将JavaScript关联数组转换为JSON? 我尝试了以下方法: var AssocArray = new Array(); AssocArray["a"] = "The letter A" console.log("a = " + AssocArray["a"]); // result: "a = The letter A" JSON.stringify(AssocArray); // result: "[]"


6
将fitBounds()与Google Maps API V3结合使用后,使用setZoom()
我正在使用fitBounds()在地图上设置缩放级别,也包括当前显示的所有标记。但是,当我只看到一个标记时,缩放比例为100%(...我认为是20的缩放比例...)。但是,我不希望它被放大得那么远,以便用户无需缩小就可以调整标记的位置。 我有以下代码: var marker = this.map.createMarker(view.latlng, this.markerNumber); this.map.bounds.extend(view.latlng); this.map.map.setCenter(this.map.bounds.getCenter()); this.map.map.fitBounds(this.map.bounds); if (this.markerNumber === 1) { this.map.map.setZoom(16); } this.markerNumber++; 之前this.map.bounds定义为: this.map.bounds = new google.maps.LatLngBounds(); 但是,我遇到的问题是,this.map.map.setZoom(16);如果使用this.map.map.fitBounds(this.map.bounds);,则该行不起作用,但是,我知道代码行是正确的,因为当我注释掉fitBound()行时,setZoom()会神奇地开始运行。 有什么想法可以解决吗?如果无法正常工作,我正在考虑设置maxZoom级别作为替代。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.