jQuery中的无限循环(Infinite loop in jQuery)
我有一个jQuery的问题,出于某种原因,代码使无限循环:
$(document).ready(function () { function changeURL() { location.href = 'http://aaa.com'; } $('#daysLeftSort').change(changeURL()); });
I have a problem with jQuery, for some reason, that code makes infinite loop:
$(document).ready(function () { function changeURL() { location.href = 'http://aaa.com'; } $('#daysLeftSort').change(changeURL()); });
原文:https://stackoverflow.com/questions/4460929
更新时间:2022-06-10 20:06
最满意答案
看来,问题出在这一行:
textField.text = currencyFormatter.stringFromNumber((text as NSString).doubleValue / 100.0)
它必须是编译器错误。 我找到的解决方法是:
// Explicitly cast as `NSNumber` textField.text = currencyFormatter.stringFromNumber((text as NSString).doubleValue / 100.0 as NSNumber) // or explicitly construct `NSNumber` from `Double` textField.text = currencyFormatter.stringFromNumber(NSNumber(double: (text as NSString).doubleValue / 100.0)) // or prepare `Double` outside let doubleVal = (text as NSString).doubleValue / 100.0 textField.text = currencyFormatter.stringFromNumber(doubleVal) // or convert `String` to `Double` without casting to `NSString`. textField.text = currencyFormatter.stringFromNumber( atof(text) / 100.0)
重现此问题的最小代码是:
let str = "42" let a:NSNumber = (str as NSString).doubleValue / 100.0
Swift 1.1 / Xcode 6.1.1成功编译,但Swift 1.2 / Xcode 6.3 Beta2崩溃。
It seems, the problem is in this line:
textField.text = currencyFormatter.stringFromNumber((text as NSString).doubleValue / 100.0)
It must be a compiler bug. The workarounds I found are:
// Explicitly cast as `NSNumber` textField.text = currencyFormatter.stringFromNumber((text as NSString).doubleValue / 100.0 as NSNumber) // or explicitly construct `NSNumber` from `Double` textField.text = currencyFormatter.stringFromNumber(NSNumber(double: (text as NSString).doubleValue / 100.0)) // or prepare `Double` outside let doubleVal = (text as NSString).doubleValue / 100.0 textField.text = currencyFormatter.stringFromNumber(doubleVal) // or convert `String` to `Double` without casting to `NSString`. textField.text = currencyFormatter.stringFromNumber( atof(text) / 100.0)
The minimum code that reproduces this problem would be:
let str = "42" let a:NSNumber = (str as NSString).doubleValue / 100.0
Swift 1.1/Xcode 6.1.1 compiles it successfully, but Swift 1.2/Xcode 6.3 Beta2 crashes.
相关问答
更多-
node.js分段错误:11(node.js segmentation fault:11)[2023-08-24]
从Node 0.4升级到0.6后,我有了这个。 我只需要从我的应用程序中删除node_modules目录,并再次使用'npm install'重新安装依赖项。 Never mind. Just used homebrew to install node.js/npm and all working fine now. Thanks anyway. -
看来,问题出在这一行: textField.text = currencyFormatter.stringFromNumber((text as NSString).doubleValue / 100.0) 它必须是编译器错误。 我找到的解决方法是: // Explicitly cast as `NSNumber` textField.text = currencyFormatter.stringFromNumber((text as NSString).doubleValue / 100.0 as NS ...
-
最糟糕的是最糟糕的重新整合吊舱 1)解体它“pod deintegrate” https://github.com/CocoaPods/cocoapods-deintegrate 2)sudo gem卸载pods然后重新安装它 3)删除Pod文件目录删除Podfile.lock并执行干净的pod安装 4)测试pod更新现在正在运行,所有后续时间你都可以进行pod更新,你可以测试并验证它在安装后不会出现段错误 worst comes to worst reintegrate pods by 1) deinte ...
-
原来我正在试图使用一个结构作为一个单身。 我打开单文件优化,以更好地了解指向带有该结构的文件的问题。 从那里,我将此结构更改为一个类,以便它仍然可以用作单例,并且现在编译代码。 Turns out I was using trying to use a struct as a singleton. I turned on single-file optimization to get a better look at the problem which pointed me to the file with ...
-
分段错误:11与swift(Segmentation fault: 11 with swift)[2023-09-05]
问题是这段代码: @IBAction func one(_ sender: AnyObject) { defaults.set(1, forKey: "Sphere") print("Ghost one was selected") } 你发现了编译器错误。 尝试解决这个问题: @IBAction func one(_ sender: AnyObject) { defaults.set(1 as Any, forKey: "Sphere") print("Ghost one ... -
找到导致我的问题的原因: 我在项目中有“Math.h”自定义文件和类,导入和使用它会导致问题。 最奇怪的是,这个文件在过去的18天里都在项目中,但一切正常。 我想,这取决于我如何使用它,在Objective-C项目中使用它,不会引起任何问题。 Found what has caused my issue: I've had "Math.h" custom file and class in project, importing and using it caused an issue. The strang ...
-
Swift编译器错误:segementation fault:存档上的11(Swift compiler error: segmentation fault: 11 on Archive)[2022-01-19]
代码中的开关缺少swfit所需的默认情况。 您可以轻松纠正此问题: func matrixOperationRequiresScalar(operation: MatrixOperation) -> Bool { switch operation { case .Addition, .Subtraction, .Multiplication, .Division, .Negative, .Determinant, .Inverse, .Transpose, .EigenOps: return ... -
崩溃与分段错误:11是Swift编译器的错误,您应该向Apple或swift.org发送错误报告。 在Swift 3中,代码中的某些错误通常会触发此编译器错误。 在您的情况下,您不能在实例属性的初始值中使用self 。 解决这个问题的一种方法是使用lazy : lazy private(set) var cellSwitch: UISwitch = { let cellSwitch = UISwitch() cellSwitch.translatesAutoresizingMaskIntoC ...
-
解决了它。 问题是两件事:1)转换为Double 2)处理一个空数组 转换为双倍 从var lat: Double? = d["lat"].doubleValue改变var lat: Double? = d["lat"].doubleValue var lat: Double? = d["lat"].doubleValue到var lat: Double? = Double(d["lat"].doubleValue) var lat: Double? = Double(d["lat"].doubleValu ...
-
是的,这个问题让我好几天......我终于通过启用整个模块优化找到了解决方案。 这是一个解释如何: http://useyourloaf.com/blog/swift-whole-module-optimization/ 祝你好运! Yea that issue kept me up for days...I finally found the solution by enabling whole module optimisation. Here's a link that explains how to ...