Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使此错误消息不打印两次?(如何使ng按键不触发ng模糊)_Javascript_Html_Angularjs_Coffeescript - Fatal编程技术网

Javascript 如何使此错误消息不打印两次?(如何使ng按键不触发ng模糊)

Javascript 如何使此错误消息不打印两次?(如何使ng按键不触发ng模糊),javascript,html,angularjs,coffeescript,Javascript,Html,Angularjs,Coffeescript,问题:symc\u invalid\u pin\u name(具有无效字符,如/、>,等等)生成的错误消息打印了两次 我的调查:由于当文本框在其他地方单击鼠标而失去焦点时,错误消息只会打印一次,而当我在文本框上聚焦时按enter键时,错误消息会打印两次,因此我认为这是因为ng按键触发ng模糊。当我在寻找解决方案时,我看到了。但是我不认为这个答案有多大帮助,因为第一个答案只是提供了概念,而不是解决方案,第二个答案是使用jQuery而不是AngularJS(我可能错了,因为我是web开发新手)。另外

问题:
symc\u invalid\u pin\u name
(具有无效字符,如/、>,等等)生成的错误消息打印了两次

我的调查:由于当文本框在其他地方单击鼠标而失去焦点时,错误消息只会打印一次,而当我在文本框上聚焦时按enter键时,错误消息会打印两次,因此我认为这是因为ng按键触发ng模糊。当我在寻找解决方案时,我看到了。但是我不认为这个答案有多大帮助,因为第一个答案只是提供了概念,而不是解决方案,第二个答案是使用jQuery而不是AngularJS(我可能错了,因为我是web开发新手)。另外,我想确定导致问题的原因是ng按键触发了ng模糊

HTML:


A26
咖啡脚本:

$scope.pinNameChanged = (e, p) ->
id = p.id
switch e.keyCode
  when 13
    illegalChars = new RegExp("[$\'\"\\\\<>`\\s]")
    pinToBeChanged = pin for pin in $rootScope.pins when pin.id is id
    if illegalChars.test($scope.editedPinNames[id].trim())
      $rootScope.$emit("GenericError", i18n.symc_invalid_pin_name)
      $scope.changedPin.id = ""
    else
      if $scope.editedPinNames[id].trim() is ""
        matchedPin = $rootScope.masterTerminals.filter ((t) -> t.jedecName is p.jedecName)[0]
        if matchedPin?
          $scope.editedPinNames[id] = if matchedPin.label? then matchedPin.label else ""
        else
          $scope.editedPinNames[id] = ""
      else
        $scope.editedPinNames[id] = $scope.editedPinNames[id].trim()
      $rootScope.$emit('PinPropertyUpdate', [id], name: $scope.editedPinNames[id])
      $rootScope.updateStandardSvg()
      $rootScope.$emit('Redraw')
      $scope.changedPin.id = ""
  when 27
    cancelPinNameEdit()

$scope.pinNameEditBlur = (e, p) -> $scope.pinNameChanged({keyCode: 13}, p)
$scope.pinNameChanged=(e,p)->
id=p.id
开关e.keyCode
13岁时
illegalChars=new RegExp(“[$\'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\s]”)
pinToBeChanged=当pin.id为id时,$rootScope.pins中的pin的pin
if illegalChars.test($scope.editedPinNames[id].trim())
$rootScope.$emit(“GenericError”,i18n.symc\u无效\u pin\u名称)
$scope.changedPin.id=“”
其他的
如果$scope.editedPinNames[id].trim()为“”
matchedPin=$rootScope.masterTerminals.filter((t)->t.jedecName是p.jedecName)[0]
如果匹配PIN?
$scope.editedPinNames[id]=如果匹配pin.label?则匹配pin.label else“”
其他的
$scope.editedPinNames[id]=“”
其他的
$scope.editedPinNames[id]=$scope.editedPinNames[id].trim()
$rootScope.$emit('PinPropertyUpdate',[id],name:$scope.editedPinNames[id])
$rootScope.updateStandardSvg()
$rootScope.$emit('Redraw')
$scope.changedPin.id=“”
27岁时
取消编辑()
$scope.pinNameEditBlur=(e,p)->$scope.pinNameChanged({keyCode:13},p)
我正在使用AngularJS。

您可以添加

ng-blur="$event.preventDefault()"
甚至对于您的产品,$event,pin)添加


但使用此选项,在文本框外单击不会使文本框失去焦点,对吗?因此,尽管按enter键不会使错误消息打印两次,但在文本框外单击会使错误消息打印0次而不是一次。
ng-blur="$event.preventDefault()"
$event.preventDefault() or $event.stopPropagation()