首页 \ 问答 \ jQuery中的无限循环(Infinite loop in jQuery)

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 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 ...
  • 问题是这段代码: @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 ...
  • 代码中的开关缺少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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)