[英]HTML/JavaScript Button - link to a URL, that is being stored as a variable?
我正在构建一个HTML页面,作为页面的一部分,我有一个链接到另一个页面的按钮,该按钮在AngularJS中设置为变量。
这是我当前无法使用的按钮的示例:
<input type="button" onclick="window.open({{profile.link}})" value="Go to Profile"/>
显然,取决于用户,链接会更改-这意味着我无法使用固定变量。
这也将在localhost:8000上运行,并将打开Internet上的外部页面。
有人对我如何实现这一目标有任何想法吗?
谢谢!
ps {{profile.link}}没什么问题,因为我已经对此进行了测试,并且它的值正确。
如果我理解正确,那么您的意思是不应为每个用户更改链接,对吗? 在这种情况下,可以在另一个地方声明“链接变量”(它可以是不同的角度范围,根范围等)。
请尝试以下操作:
<input type="button" onclick="window.open({{someanotherscope.link}})" value="Go to Profile"/>
您可以使用ng-click =“ window.open(profile.link)”代替onclick
var test = angular.module('test', []); test.controller('testController', ['$scope','$window', function($scope, $window) { $scope.profile = { "link": 'http://www.google.com'}; $scope.openWindow = function() { $window.open($scope.profile.link, 'Title', 'width=500,height=400'); };}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="test" ng-controller="testController"> <input type="button" ng-click="openWindow()" value="Go to Profile"/> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.