Uncaught SyntaxError:意外的标识符。为什么?

时间:2015-09-27 09:39:20

标签: javascript string syntax-error identifier

我在此行中收到未捕获的SyntaxError:意外的标识符错误

if(v=="ZP31"||v=="ZC31"||v=="SX31"||v=="SX71"||v=="SW71"||v=="XM71"||v=="1Z21"){return "<span class="label label-default">Default</span>";}

缺少哪个标识符?

谢谢:)

2 个答案:

答案 0 :(得分:2)

您的字符串嵌套不正确。

你要么逃避双引号,

return '<span class="label label-default">Default</span>';

或更改为单引号:

import iAd
class GameViewController: UIViewController, ADInterstitialAdDelegate {

var interAd:ADInterstitialAd?
var interAdView = UIView()
var closeButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton

override func viewDidLoad() {
    super.viewDidLoad()

    closeButton.frame = CGRectMake(20, 20, 70, 44)
    closeButton.layer.cornerRadius = 10
    closeButton.backgroundColor = UIColor.whiteColor()
    closeButton.layer.borderColor = UIColor.blackColor().CGColor
    closeButton.layer.borderWidth = 1
    closeButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
    closeButton.addTarget(self, action: "closeAd:", forControlEvents: UIControlEvents.TouchDown)
    closeButton.enabled = false
    closeButton.setTitle("skip", forState: UIControlState.Normal)
    closeButton.enabled = true
    closeButton.setNeedsLayout()

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "showAd", name: "showIntAD", object: nil)

func prepareAd() {
    println(" --- AD: Try Load ---")
    // Attempt to load a new ad:
    interAd = ADInterstitialAd()
    interAd?.delegate = self
}

func showAd() -> Bool {
    if interAd != nil && interAd!.loaded {
        interAdView = UIView()
        interAdView.frame = self.view!.bounds
        self.view?.addSubview(interAdView)

        interAd!.presentInView(interAdView)
        UIViewController.prepareInterstitialAds()

        interAdView.addSubview(closeButton)
    }
    return interAd?.loaded ?? false
}

func closeAd(sender: UIButton) {
    adFinished()
}

func adFinished() {
    closeButton.removeFromSuperview()
    interAdView.removeFromSuperview()
}

func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
    println(" --- AD: Load Success ---")
}

func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
    println(" --- AD: Unload --- ")
}

func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
    println(" --- ADD: Action Finished --- ")
    adFinished()
}

func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {
    return true
}

func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
    println(" --- AD: Error --- ")
    println(error.localizedDescription)
    }
}

答案 1 :(得分:0)

您必须像以下一样转义HTML返回字符串:

"<span class=\"label label-default\">Default</span>"