簡體   English   中英

PHP中的HTML和Javascript代碼

[英]HTML & Javascript Code within PHP

標題怎么樣?

我再次發現自己陷入了我不真正理解的代碼行中,並且這樣做幾乎在每個障礙中都失敗了。

我有一個php文件xxxxx.php,我想做的是:從一個javascript函數中,設置一個div的屬性,然后執行更多的javascript-我確定對於理解的人來說很容易(但是顯然不適合我)

這段代碼可以正常運行:

<script type="text/javascript">
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
{
alert("Welcome again " + username);
}
else
{
username=prompt("Please enter your name:","");

if (username!=null && username!="")
{
setCookie("username",username,7);
}
}
}
</script>
</head>
<body onload="checkCookie()">
</body>

但是,我想直接在“ setCookie”行之后插入以下代碼(本身可以正常工作):

<div style="position:absolute;top:125px;left:-67px;z-index:10000000">
<script src="AC_RunActiveContent.js" type="text/javascript"></script>

<script type="text/javascript">
AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay=true&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer'); //end AC code

</script> </div>

任何想法或建議,將不勝感激。

我嘗試使用以下方法在javascript中設置div樣式:

var div = document.createElement('div');
div.style.position = 'absolute';
div.style.top = "125px";
div.style.left = "-67px";
div.style.zIndex = "10000000";
document.body.appendChild(div);

...但是這只是將Flash Player(用'AC_FL_RunContent'行調用)放到了一個新的空白頁面上,而不是在現有頁面內(根據需要)。

希望有人能夠理解我的雜談。

搶。

似乎帶有<div>標簽的新代碼位於主<head>標簽內-它將無法正常工作,請嘗試將新代碼放入<body>標簽內。

另一件事,就是不能像這樣在<script>內放置任何html標簽。 您必須document.write他們在某個地方。

編輯

setCookie();之后使用這樣的setCookie();

document.write('<div style="position:absolute;top:125px;left:-67px;z-index:10000000">');
document.write('<script src="AC_RunActiveContent.js" type="text/javascript"></script>');
document.write("<script type=\"text/javascript\"> AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay=true&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer'); //end AC code</script> </div>");

希望對您有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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