@sunny-lan, even if you write the pin to be INPUT, there's still a protection diode from the IO pin to VDD inside the microcontroller. So if your VDD is 3 volts, you're basically still pulling the pin low to 3.6 volts even if you set the pin as INPUT. If you set it as OUTPUT, LOW then you're pulling it low to zero volts.
I know everybody is saying that you shouldn't connect the IO pin to a 24V pulled up pin, and they're basically right. But the only way to be sure is to find the absolute maximum ratings in the datasheet and I cannot find them. 10 k pull-up to 24 volts is 2.4 milliamps and the protection diode just might be able to sink that amount of current. But whether you could control the external device or not, that's another matter. Remember, you're only going to be able to make a 3.6V difference in the voltage at the MCUs end. Depending entirely on what is the Vil/Vih decision level point in the external equipment, you might be able to find a series resistor value that allows you to swing over that decision threshold.
But you're basically probably going to destroy your ESP8266 in the process. Especially if your ESP is unpowered and there's nothing to sink that current, and the 2.4mA from the pin lifts the power rail over something like 5 volts, the chip is dead. And the NPN suggested by Umar only costs something like 2 cents US or less than 0.1 RMB so why not use it. It's the only practical way to do it, really...