簡體   English   中英

HTML / JavaScript按鈕-鏈接到URL,該URL是否存儲為變量?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM