在php中使用javascript制作关闭按钮

For closing a <div>, I use onclick="this.parentNode.style.display='none';" (in HTML) and it works. But in PHP it doesn't work!

error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/u381013597/> public_html/index.html on line 311

When I change 'none' to "none" there is no error but the close item doesn't work.
What is the problem?

When you print in PHP you have to watch out with strings. You define a string with single or double quotes. If your string contains for example single quotes and you defined the string with a single quote the quote in the string itself will mean end of string, so you have to escape them:

echo 'onclick="this.parentNode.style.display=\'none\';"';

As you see I used single quotes for printing here, and I escaped every single quote in the string itself with the backslash character: \

Otherwise, the string would ended before none (because there is a unescaped single quote that means the end of the string) and the parser would except a ; character that means end of command or a , character that marks that there will be other parameters, but you give none of them, it gets none instead. Thats why it throws that he get an unexpected T_STRING. If you look at your error message, you will see that it says the same as I did, just in a compact way:

error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/u381013597/> public_html/index.html on line 311

It also says that there is a Parse error: syntax error that means you mistyped something, and he also says where does the problem occurs.

Error messages are your friends, they give a hint about the problem. Read (or at least search for) them and you will be able to develop much faster.