我是JS和Swift开发人员的新手。我有一个具有此属性的按钮:
<a href="http://phonefiveme.com/nocontact" id="yui_3_17_2_1_1490136681073_127" style="cursor: url("chrome-extension://ledmjlnkdlappilhaaihfhanlpdjjalm/rockhand.png"), auto;">
我需要做的是将href编辑为存储在变量中的链接。这就是我所拥有的:
var currentLocation = window.location;
var stringURL = String(currentLocation);
var shortened = stringURL.substring(32);
var myElement = document.getElementById("yui_3_17_2_1_1490136681073_127");
我只需要替换&#34; http://phonefiveme.com/nocontact&#34;与shortened
任何帮助将不胜感激!非常感谢。 干杯, 西奥
答案 0 :(得分:2)
您可以使用href JavaScript属性执行此操作。
只需添加到您的JavaScript:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
server {
listen 8008;
server_name localhost;
set $elb "<<my elb url>>";
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
if ($request_method !~ ^(GET|POST)$ )
{
return 405;
}
location / {
resolver 172.16.0.2 valid=10s;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass $elb;
}
location /login {
deny all;
return 404;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
有关详情,请参阅similar问题。
答案 1 :(得分:1)
简单:
var currentLocation = window.location;
var stringURL = String(currentLocation);
var shortened = stringURL.substring(32);
var myElement = document.getElementById("yui_3_17_2_1_1490136681073_127");
myElement.href = myElement.href.replace("http://phonefiveme.com/nocontact", shortened);
答案 2 :(得分:1)
您可以访问html元素的属性,只需使用
myElement.href=shortened;
要做的伎俩