草庐IT

document_number

全部标签

javascript - TypeScript 2.4.1 -> fontWeight -> 类型 'number' 不可分配给类型 '"inherit"| 400 |

当我尝试在TypeScript中设置fontWeight时出现此错误:Typesofproperty'test'areincompatible.Type'{fontWeight:number;}'isnotassignabletotype'Partial'.Typesofproperty'fontWeight'areincompatible.Type'number'isnotassignabletotype'"inherit"|400|"initial"|"unset"|"normal"|"bold"|"bolder"|"lighter"|100|200|30...'.即使400是一个

javascript - JS : regex for numbers and spaces?

我正在使用happyJS并使用下面的正则表达式进行电话验证phone:function(val){return/^(?:[0-9]+$)/.test(val);}但是这只允许数字。我希望用户能够像输入空格一样23823845383知道为什么return/^(?:[0-9]+$)/.test(val);没有成功吗? 最佳答案 这是我建议的解决方案:/^(?=.*\d)[\d]+$/.test(val)(?=.*\d)断言输入中至少有一位数字。否则,只有空格的输入可以匹配。请注意,这不会对数字的数量施加任何限制(仅确保至少有1位数字),

javascript - $(document).on() 在纯 JavaScript 中?

在jQuery中有.on()可以用作:$(document).on('click','.foo',function(){/*...*/});这会监听所有类.foo的DOM元素上的点击事件。但是,这也会监听以后添加到DOM中的任何最终元素,因此它不等于:varelements=document.getElementsByClassName('foo');for(varelementinelements){element.addEventListener('click',function(){/*...*/});}我如何在纯JavaScript中执行此操作?我应该使用MutationObs

javascript - document.observe ('dom:loaded' , 函数 () {

有没有办法让这个原型(prototype)js只在dom发生变化而没有加载时触发? 最佳答案 你可以观察到元素是这样变化的$('element').observe('change',function(e){});这是为表单元素保留的-textarea、select和input。最终代码看起来像这样:document.observe('dom:loaded',function(){$('element').observe('change',function(e){//dosomethinghere});});

javascript - document.createElement ('script' ).src = 变量?是否可以?

是否可以创建类似于:varjsfile="code....";(a=(b=document).createElement('script')).src=jsfile;b.body.appendChild(a);其中“jsfile”就像一个外部js文件,但在我们的例子中是一个变量?我所有的测试都失败了,我成功地获得了“jsfile”的输入,但是如果obj中有函数(记住我希望它像外部js文件一样执行),它们就不会执行。测试示例:varjsfile="code....";(a=(b=document).createElement('script')).text=(jsfile);b.body

JavaScript 在 document.write 中嵌入 <script> 标签不起作用

我不确定我的代码有什么问题,但是当我尝试添加actorWin.document.write('')时一切都搞砸了。没有这一行,代码工作正常。createawindowfunctionMovie(title,actor){this.title=title;this.actor=actor;}vardocumentary=newMovie('http://www.imdb.com/title/tt0358456/?ref_=fn_al_tt_2','http://en.wikipedia.org/wiki/Joaquin_Phoenix');varmovieWin=newObject();

javascript - 如何访问 Aurelia 中的 Window 和 Document 对象?

访问ES6/Aurelia框架中的Document和Window对象的最佳方式是什么?我确实尝试在我的Aurelia代码中直接访问window,它似乎确实有效,但这是正确的方法还是有Aurelia/ES6的方法?具体来说,我想访问像window.localStorage这样的属性和window.sessionStorage.我刚开始使用Aurelia和ES6,所以虽然我想遵循标准,但我对如何做这件事有点菜鸟。类似下面的内容:constructor(){this.user=JSON.parse(window.sessionStorage.user||window.localStorage

javascript - document.onkeypress 不工作,如何解决?

是否有任何原因导致以下代码不应在我的控制台日志中返回任何内容?!document.onkeypress=zx();functionzx(){console.log(event.keyCode);}//zxwindow.onkeypress也不起作用。还有其他尝试,例如:document.onkeypress=zx(event);functionzx(event){console.log(event.keyCode);}//zx-document.onkeypress=zx;functionzx(){console.log(event.keyCode);}//zx谢谢!

javascript - document.getElementById ('' ).src == ??? (等于失败)

我的javascript是functionchangeImage(imgID){varbaseurl="media/images/";if(document.getElementById(imgID).src==baseurl+"selection-off.png"){alert('Success');document.getElementById(imgID).src=baseurl+"selection-no.png";}else{alert('Fail');}}我的HTML是点击图片时总是失败。我一定是遗漏了一些非常基本的东西。 最佳答案

javascript - 为什么 ▶ 的 HTML 符号在 document.title 中不起作用

我尝试在设置document.title时使用►但它没有呈现播放符号,只是显示了那些相同的字符。我可以将▶直接粘贴到有效的代码中。我很好奇为什么第一种方法行不通。谢谢! 最佳答案 ►是HTML实体引用,但是document.title不包含HTML;它包含纯文本。例如,如果我设置document.title至Helloworld,它会按字面意思显示,而不是显示Helloworld。这同样适用于任何其他HTML片段,包括实体引用。明确地说,您可以在title中包含实体引用标签。解析页面时将解释它们。然而,document.